#include <stdlib.h>
#include <unistd.h>
#include "dunQueue.h"

int queuePop(dunQueue *pq)
{
  int		x;
  dunQueue	q;
  q = *pq;
  x = q->prev->cont;
  if (q==q->prev)
    {
      free(q);
      q = NULL;
    }
  else
    {
      q = q->prev;
      (*pq)->prev = q->prev;
      (*pq)->prev->next = *pq;
      free(q);
      q = *pq;
    }
  *pq = q;
  return (x);
}

dunQueue queuePush(int x, dunQueue q)
{
  dunQueue tmp;
  tmp = malloc(sizeof (struct s_queue));
  tmp->cont = x;
  if (q)
    {
      tmp->next = q;
      tmp->prev = q->prev;
      tmp->prev->next = tmp;
      q->prev = tmp;
    }
  else
    tmp->prev = tmp->next = tmp;
  return tmp;
}

dunQueue	stackPush(int x, dunQueue s)
{
	dunQueue tmp = malloc(sizeof (struct s_queue));
	tmp->cont = x;
	tmp->next = s;
	return (tmp);
}

int			stackPeak(dunQueue s)
{
	return (s->cont);
}

int		stackPop(dunQueue *s)
{
	dunQueue tmp = (*s)->next;
	int res = (*s)->cont;
	free(*s);
	*s = tmp;
	return (res);
}
